﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using Runda.CMS.Common.Entity;
using Runda.CMS.Bll;

namespace Runda.CMS.Portal.SysManage
{
    public partial class DepartmentAdd : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["ParentID"] != null)
                {
                    SysDepartmentEntity entity = new SysDepartmentEntity();
                    SysDepartmentBll bll = new SysDepartmentBll();
                    entity = bll.Get<SysDepartmentEntity>(new Guid(Request.QueryString["ParentID"]));
                    if (entity != null)
                    {
                        txtPartent.Text = entity.DepartmentName;
                    }
                }
            }
        }

        protected void btnOK_Click(object sender, EventArgs e)
        {
            if (txtDeptName.Text.Trim() == "")
            {
                ClientScript.RegisterStartupScript(this.GetType(), "err", "alert('请输入部门名称!');", true);
                return;
            }

            SysDepartmentEntity entity = new SysDepartmentEntity();
            entity.DepartmentName = txtDeptName.Text;
            if(Request.QueryString["ParentID"] != null)
            entity.ParentID = new Guid(Request.QueryString["ParentID"]);
            entity.CreatedOn = DateTime.Now;
            entity.CreatedBy = CurrentUserID;

            SysDepartmentBll bll = new SysDepartmentBll();
            bll.InsertOrUpdate(entity);
            ClientScript.RegisterStartupScript(this.GetType(), "success", "alert('保存成功!');window.close();", true);
        }

    }
}
